import java.io.FileOutputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.*;

public class CreateXML {

    /**
     * @param args
     */
    public static void main(String[] args) {
	try{
	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
	DocumentBuilder builder = factory.newDocumentBuilder();

	Document doc = builder.newDocument();

	Element rootElement = doc.createElement("root");
	Element childElement = doc.createElement("child");
	
	doc.appendChild(rootElement);
	
	rootElement.setAttribute("one", "two");	
	rootElement.appendChild(childElement);
	
	childElement.setAttribute("three", "four");
	Text textChildNode = doc.createTextNode("root-root-root");

	childElement.appendChild(textChildNode);

	Transformer t = TransformerFactory.newInstance().newTransformer();

	t.transform(new DOMSource(doc), new StreamResult(new FileOutputStream(
		"C:\\333.xml")));
	
	}catch (Exception ex){
	    ex.printStackTrace();
	}
    }

}
